!> author: 左志华
!> date: 2022-07-16
!>
!> 运行测试: `> meson test engine`
program tester

    use, intrinsic :: iso_fortran_env, only: error_unit
    use testdrive, only: run_testsuite, new_testsuite, testsuite_type
    use test_load_toml_m, only: collect_load_toml
    use test_sph_smoothed_kernel_function, only: collect_kernel_function
    use test_sph_density_summation, only: collect_density_summation
    use test_sph_eos, only: collect_EoS
    use test_sph_external_force, only: collect_external_force
    use test_sph_internal_force, only: collect_internal_force
    use test_math_m, only: collect_math
    implicit none
    integer :: stat, is
    type(testsuite_type), allocatable :: testsuites(:)
    character(len=*), parameter :: fmt = '("#", *(1x, a))'

    stat = 0

    allocate (testsuites, source=[ &
              new_testsuite("MODULE: sph_smoothed_kernel_function", collect_kernel_function), &
              new_testsuite("MODULE: sph_density_summation", collect_density_summation), &
              new_testsuite("MODULE: sph_eos", collect_EoS), &
              new_testsuite("MODULE: sph_external_force", collect_external_force), &
              new_testsuite("MODULE: sph_internal_force", collect_internal_force), &
              new_testsuite("MODULE: sph_load_toml", collect_load_toml), &
              new_testsuite("MODULE: sph_math", collect_math) &
              ])

    do is = 1, size(testsuites)
        write (error_unit, fmt) "Testing:", testsuites(is)%name
        call run_testsuite(testsuites(is)%collect, error_unit, stat, parallel=.true.)
    end do

    if (stat > 0) then
        write (error_unit, '(i0, 1x, a)') stat, "test(s) failed!"
        error stop
    end if

end program tester
